<template>
<view class="content">
	<view class="box" :style='{"minHeight":"100%","width":"100%","padding":"0","position":"relative","background":"#FFFFFF","height":"auto"}'>
		<view :style='{"width":"100%","padding":"24rpx","background":"none","display":"block","height":"auto"}'>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>账号</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' disabled="true"  v-model="ruleForm.laorendianhua" placeholder="请输入账号"></input>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>姓名</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.xingming" placeholder="请输入姓名"></input>
			</view>
			<view v-if="tableName=='laoren'" :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}' class="title">性别</view>
				<picker :style='{"width":"100%","flex":"1","height":"auto"}'  @change="laorenxingbieChange" :value="laorenxingbieIndex" :range="laorenxingbieOptions">
					<view :style='{"borderColor":"#828282","color":"#000","borderWidth":"0 0 2rpx 0 ","width":"100%","lineHeight":"80rpx","fontSize":"28rpx","borderStyle":"solid"}' class="uni-input picker-select-input">{{ruleForm.xingbie?ruleForm.xingbie:"请选择性别"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>电话</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.laorendianhua" placeholder="请输入电话" disabled="true"></input>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" @tap="laorentouxiangTap" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>头像</view>
				<image :style='{"width":"80rpx","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' v-if="ruleForm.touxiang" style="margin: 0;" class="avator" :src="baseUrl+ruleForm.touxiang" mode=""></image>
				<image :style='{"width":"80rpx","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' v-else class="avator" style="margin: 0;" src="../../static/gen/upload.png" mode=""></image>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>积分</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' disabled="true"  v-model="ruleForm.jifen" placeholder="请输入积分"></input>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>账号</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' disabled="true"  v-model="ruleForm.yuangongdianhua" placeholder="请输入账号"></input>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>姓名</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.yuangongxingming" placeholder="请输入姓名"></input>
			</view>
			<view v-if="tableName=='yuangong'" :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' class=" select">
				<view :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}' class="title">性别</view>
				<picker :style='{"width":"100%","flex":"1","height":"auto"}'  @change="yuangongxingbieChange" :value="yuangongxingbieIndex" :range="yuangongxingbieOptions">
					<view :style='{"borderColor":"#828282","color":"#000","borderWidth":"0 0 2rpx 0 ","width":"100%","lineHeight":"80rpx","fontSize":"28rpx","borderStyle":"solid"}' class="uni-input picker-select-input">{{ruleForm.xingbie?ruleForm.xingbie:"请选择性别"}}</view>
				</picker>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>电话</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.yuangongdianhua" placeholder="请输入电话" disabled="true"></input>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" @tap="yuangongtouxiangTap" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>头像</view>
				<image :style='{"width":"80rpx","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' v-if="ruleForm.touxiang" style="margin: 0;" class="avator" :src="baseUrl+ruleForm.touxiang" mode=""></image>
				<image :style='{"width":"80rpx","borderRadius":"100%","objectFit":"cover","display":"block","height":"80rpx"}' v-else class="avator" style="margin: 0;" src="../../static/gen/upload.png" mode=""></image>
			</view>
			<view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" class="">
				<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>积分</view>
				<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' disabled="true"  v-model="ruleForm.jifen" placeholder="请输入积分"></input>
			</view>
			  <view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='yuangong'" class="">
			  	<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>服务地址</view>
			  	<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.zhuzhi" placeholder="请输入服务地址"></input>
			  </view>
			  <view :style='{"padding":"12rpx 0","margin":"0 0 24rpx 0","borderColor":"rgb(119, 47, 26)","alignItems":"center","borderWidth":"0","display":"flex","width":"100%","borderStyle":"solid","height":"auto"}' v-if="tableName=='laoren'" class="">
			  	<view class="title" :style='{"padding":"0 10rpx 0 0","whiteSpace":"nowrap","color":"#333","textAlign":"right","width":"auto","lineHeight":"80rpx","fontSize":"28rpx","fontWeight":"600"}'>服务地址</view>
			  	<input :style='{"padding":"0px 24rpx","margin":"0px","borderColor":"#828282","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"rgba(255, 255, 255, 0)","borderWidth":"0 0 2rpx 0","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'   v-model="ruleForm.zhuzhi" placeholder="请输入服务地址"></input>
			  </view>
			<view :style='{"width":"100%","justifyContent":"center","display":"flex","height":"auto"}' class="btn">
				<button @tap="update()" class="cu-btn lg" :style='{"border":"0","padding":"0px","margin":"0 20rpx","color":"#fff","borderRadius":"10rpx","background":"linear-gradient( 135deg, #9EF0EA 0%, #99ABFF 100%)","width":"200rpx","lineHeight":"80rpx","fontSize":"28rpx","height":"80rpx"}'>保存</button>
				<button @tap="logout()" class="cu-btn lg" :style='{"border":"0","padding":"0px","margin":"0 20rpx","color":"#808080","borderRadius":"10rpx","background":"#DEDEDE","width":"200rpx","lineHeight":"80rpx","fontSize":"28rpx","height":"80rpx"}'>退出登录</button>
			</view>
		</view>
	</view>
</view>
</template>

<script>

    import xiaEditor from '@/components/xia-editor/xia-editor';
    import multipleSelect from "@/components/momo-multipleSelect/momo-multipleSelect";
	export default {
		data() {
			return {
				ruleForm: {
				},
				tableName:"",
				laorenxingbieOptions: [],
				laorenxingbieIndex: 0,
				yuangongxingbieOptions: [],
				yuangongxingbieIndex: 0,
			}
		},
        components: {
            multipleSelect,
			xiaEditor
        },
		computed: {
			baseUrl() {
				return this.$base.url;
			}
		},
		async onLoad() {
			let table = uni.getStorageSync("nowTable");
			let that = this
			let res = {}
			this.tableName = table;
			this.getSession()
			// 自定义下拉框值
			if(this.tableName=='laoren'){
				this.laorenxingbieOptions = "男,女".split(',');
				this.laorenxingbieOptions.forEach((item, index) => {
					if(item==this.ruleForm.xingbie) {
						this.laorenxingbieIndex = index;
					}
				});
			}
			// 自定义下拉框值
			if(this.tableName=='yuangong'){
				this.yuangongxingbieOptions = "男,女".split(',');
				this.yuangongxingbieOptions.forEach((item, index) => {
					if(item==this.ruleForm.xingbie) {
						this.yuangongxingbieIndex = index;
					}
				});
			}
			this.styleChange()
            this.$forceUpdate()
		},
		methods: {
			async getSession(){
				let res = await this.$api.session(this.tableName)
				this.ruleForm = res.data;
				uni.setStorageSync('userSession',JSON.stringify(res.data))
			},
            // 下拉变化
            laorenxingbieChange(e) {
                    this.laorenxingbieIndex = e.target.value
                    this.ruleForm.xingbie = this.laorenxingbieOptions[this.laorenxingbieIndex]
            },
			laorentouxiangTap() {
				let _this = this;
				this.$api.upload(function(res) {
					_this.ruleForm.touxiang = 'upload/' + res.file;
					_this.$forceUpdate();
				});
			},
            // 下拉变化
            yuangongxingbieChange(e) {
                    this.yuangongxingbieIndex = e.target.value
                    this.ruleForm.xingbie = this.yuangongxingbieOptions[this.yuangongxingbieIndex]
            },
			yuangongtouxiangTap() {
				let _this = this;
				this.$api.upload(function(res) {
					_this.ruleForm.touxiang = 'upload/' + res.file;
					_this.$forceUpdate();
				});
			},

            toggleTab(str) {
                this.$refs[str].show();
            },

			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('. .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.userInfoForm.list.input.backgroundColor
					// })
				})
			},
			// 获取uuid
			getUUID () {
				return new Date().getTime();
			},
			logout() {
				uni.clearStorageSync()
				this.$utils.jump('../login/login');
			},
			// 注册
			async update() {

				if((!this.ruleForm.zhanghao) && `laoren` == this.tableName){
					this.$utils.msg(`账号不能为空`);
					return
				}

				if((!this.ruleForm.mima) && `laoren` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}

				if((!this.ruleForm.xingming) && `laoren` == this.tableName){
					this.$utils.msg(`姓名不能为空`);
					return
				}


				if(`laoren` == this.tableName && this.ruleForm.laorendianhua&&(!this.$validate.isMobile(this.ruleForm.laorendianhua))){
					this.$utils.msg(`电话应输入手机格式`);
					return
				}


				if(`laoren` == this.tableName && this.ruleForm.jifen&&(!this.$validate.isNumber(this.ruleForm.jifen))){
					this.$utils.msg(`积分应输入数字`);
					return
				}

				if(`laoren` == this.tableName && this.ruleForm.status&&(!this.$validate.isIntNumer(this.ruleForm.status))){
					this.$utils.msg(`状态应输入整数`);
					return
				}

				if((!this.ruleForm.yuangongzhanghao) && `yuangong` == this.tableName){
					this.$utils.msg(`账号不能为空`);
					return
				}

				if((!this.ruleForm.mima) && `yuangong` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}

				if((!this.ruleForm.yuangongxingming) && `yuangong` == this.tableName){
					this.$utils.msg(`姓名不能为空`);
					return
				}


				if(`yuangong` == this.tableName && this.ruleForm.yuangongdianhua&&(!this.$validate.isMobile(this.ruleForm.yuangongdianhua))){
					this.$utils.msg(`电话应输入手机格式`);
					return
				}


				if(`yuangong` == this.tableName && this.ruleForm.jifen&&(!this.$validate.isNumber(this.ruleForm.jifen))){
					this.$utils.msg(`积分应输入数字`);
					return
				}
				if((!this.ruleForm.zhuzhi)&&'laoren'==this.tableName){
					this.$utils.msg(`服务地址不能为空`);
					return
				}
				if((!this.ruleForm.zhuzhi)&&'yuangong'==this.tableName){
					this.$utils.msg(`服务地址不能为空`);
					return
				}
				let table = uni.getStorageSync("nowTable");
				await this.$api.update(table, this.ruleForm);
				this.$utils.msgBack('修改成功');;
				this.getSession()
			},

		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
